<?php

/**
 * Created by PhpStorm.
 * User: renyi
 * Date: 2017/5/10
 * Time: 下午16:51
 */

namespace App\Helper;

use Hashids\Hashids;

class HashIDHelper
{
    const token = "tcmmooc20170509";

//    public static function encode($field, $value)
//    {
//        $salt = $field.self::token;
//
//        $hashids = new Hashids($salt, 20);
//
//        return $hashids->encode($value);
//    }

    public static function decode($field, $value)
    {
        $salt = $field.self::token;

        $hashids = new Hashids($salt, 20);

        return $hashids->decode($value);
    }

     public static function encode($table, $id)
     {
         $salt = self::token . $table . $id . time();

         return md5($salt);
     }
}
